package com.mc.moring.widge;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.DashPathEffect;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PathEffect;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;

import com.mc.moring.R;

public class DashedLineDrawable extends View {

    private int mWidth;
    private int mHeight;
    private Paint mLinePaint;
    private Paint paint;
    private Path path;
    private PathEffect pathEffect;
    private int startX;

    public DashedLineDrawable(Context context) {
        this(context, null);
    }

    public DashedLineDrawable(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public DashedLineDrawable(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();

    }

    private void init() {
        paint = new Paint();
        paint.setAntiAlias(true);
        paint.setStrokeWidth(2);
        paint.setColor(Color.RED);
        paint.setStyle(Paint.Style.STROKE);

        mLinePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mLinePaint.setStrokeWidth(1);
        mLinePaint.setStyle(Paint.Style.STROKE);
        mLinePaint.setColor(getResources().getColor(R.color.colorAccent));

        path = new Path();
        startX = 120;


    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
        mWidth = w;
        mHeight = h;
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        path.moveTo(startX, 0);
        path.lineTo(startX,getHeight());
        pathEffect = new DashPathEffect(new float[]{50,50},0);
        paint.setPathEffect(pathEffect);
        canvas.drawPath(path,paint);
    }
}
